package com.situ.student.service.impl;

import java.util.List;

import com.situ.student.dao.IStudentDao;
import com.situ.student.dao.impl.StudentDaoImpl;
import com.situ.student.entity.Student;
import com.situ.student.exception.NameRepeatException;
import com.situ.student.service.IStudentService;

public class StudentServiceImpl implements IStudentService{
	//private StudentDaoImpl studentDao = new StudentDaoImpl();
	private IStudentDao studentDao = new StudentDaoImpl();
	
	@Override
	public boolean register(Student student) throws NameRepeatException {
		//1、判读这个学生还不是存在
		if (studentDao.checkName(student.getName())) {
			//System.out.println("该用户名已经存在");
			//return false;
			throw new NameRepeatException("该用户名已经存在");
		} else {//2 、这个用户名不存在
			//return studentDao.insert(student) > 0 ? true : false;
			int result = studentDao.insert(student);
			if (result > 0) {
				return true;
			} else {
				return false;
			}
		}
	}

	@Override
	public List<Student> findAll() {
		return studentDao.findAll();
	}


}
